<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增APP版本')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: summernote-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-appEdition-add">

        <div class="form-group">
            <label class="col-sm-3 control-label">appId：</label>
            <div class="col-sm-8">
                <input name="appId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">版本号：</label>
            <div class="col-sm-8">
                <input name="editionCode" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">应用名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <input name="title" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">手机型号：</label>
            <div class="col-sm-8">
                <select name="type" class="form-control m-b">
                    <option value="1">安卓</option>
                    <option value="2">苹果</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">强制更新：</label>
            <div class="col-sm-8">
                <select name="renew" class="form-control m-b">
                    <option value="是">是</option>
                    <option value="否">否</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">包类型：</label>
            <div class="col-sm-8">
                <select name="wrapType" class="form-control m-b">
                    <option value="wgt">wgt</option>
                    <option value="app">app</option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上传：</label>
            <div class="col-sm-8">
                <input type="file" name="upload" id="upload" style="display: none;"/>
                <input type="hidden" id="fileType" style="display: none;"/>
                <a class="btn btn-success" onclick="onFile()">
                    <i class="fa fa-plus"></i> 下载地址
                </a>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">下载地址：</label>
            <div class="col-sm-8">
                <input id="url" name="url" class="form-control" type="text" readonly="true">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">应用地址：</label>
            <div class="col-sm-8">
                <input id="storeUrl" name="storeUrl" class="form-control" type="text" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">内容：</label>
            <div class="col-sm-8">
                <textarea name="content" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: summernote-js"/>
<script th:inline="javascript">
    var prefix = ctx + "sso/appEdition"
    $("#form-appEdition-add").validate({
        focusCleanup: true
    });

    var isClick = true;

    function submitHandler() {
        if ($.validate.form() && isClick) {
            isClick = false;
            $.operate.save(prefix + "/add", $('#form-appEdition-add').serialize());
        }
    }

    $("input[name='created']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $(function () {
        $('.summernote').summernote({
            lang: 'zh-CN',
            dialogsInBody: true,
            callbacks: {
                onChange: function (contents, $edittable) {
                    $("input[name='" + this.id + "']").val(contents);
                },
                onImageUpload: function (files) {
                    var obj = this;
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        type: "post",
                        url: ctx + "common/upload",
                        data: data,
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $('#' + obj.id).summernote('insertImage', result.url);
                            } else {
                                $.modal.alertError(result.msg);
                            }
                        },
                        error: function (error) {
                            $.modal.alertWarning("图片上传失败。");
                        }
                    });
                }
            }
        });
    });

    function onFile() {
        $('#upload').click();
    }

    $('#upload').on('change', function () {
        var farmdate = new FormData();
        farmdate.append("file", $('#upload')[0].files[0]);
        $.ajax({
            type: "post",
            url: "/common/importFile",
            data: farmdate,
            contentType: false,
            processData: false,
            success: function (date) {
                $('#url').val(date);
            }
        })
    });
</script>
</body>
</html>